import { application as http } from '@zh/common-utils/http'

export { http }

/**
 * 分页查询
 * @param {Object} params
 */
export function page (params) {
  return http.post('app/sysApplication/page', params)
}
/**
 * 查询机构权限列表
 * @param {Long} appId  { applicationId: this.appId }
 */
export function queryUnit (appId) {
  return http.post('app/sysApplicationUnit/queryUnit', { applicationId: appId })
}
export function authApp (params) {
  return http.post('app/sysApplicationUnit/authApp', params)
}
/**
 * api树
 * @param {String} code
 */
export function queryApi (appId) {
  return http.post('app/sysApplicationApi/queryApi', { applicationId: appId })
}

/**
 * api树
 * @param {String} code
 */
export function queryApiTree (code) {
  return http.post('app/sysOpenApi/queryApiTree', { code: code })
}

/**
 * 保存应用机构权限
 * @param {Long} appId 应用ID
 * @param {Array} checkedKeysUnit 选中的机构
 */
export function saveUnit (appId, checkedKeysUnit, selectedRowKeys) {
  return http.post('app/sysApplicationUnit/insert', {
    applicationId: appId,
    unitIds: checkedKeysUnit,
    userIds: selectedRowKeys
  })
}

/**
 * 保存API
 * @param {Long} appId 应用ID
 * @param {Array} checkedKeysApi 选中的api
 */
export function saveApi (appId, checkedKeysApi) {
  return http.post('app/sysApplicationApi/insert', {
    applicationId: appId,
    openApiIds: checkedKeysApi
  })
}

/**
 * 删除
 * @param {String} id
 */
export function del (id) {
  return http.get('app/sysApplication/del/' + id)
}

export function getOrderNo () {
  return http.post('app/sysApplication/getOrderNum')
}

export function getAppSm2 () {
  return http.post('app/sysApplication/getAppSm2')
}

export function getById (id) {
  return http.get('app/sysApplication/info/' + id)
}

/**
 * 修改或保存
 * @param {Object} params
 */
export function saveOrUpdate (data) {
  const url = data.id ? 'app/sysApplication/update' : 'app/sysApplication/insert'
  return http.post(url, data)
}

/** 快捷方式 **/

/**
 * 快捷方式分页
 * @param {Object} params
 */
export function shortcutPage (params) {
  return http.post('app/sysAppShortcut/page', params)
}
/**
 * 快捷方式获取排序号
 * @param {Object} formShrotcut
 */
export function getShortcutOrderNo (formShrotcut) {
  return http.post('app/sysAppShortcut/getOrderNo', formShrotcut)
}
/**
 * 根据ID 找快捷方式
 * @param {Long} id 主键ID
 */
export function getShortcutById (id) {
  return http.get('app/sysAppShortcut/getById/' + id)
}

/**
 * 修改保存快捷
 * @param {Object} form
 */
export function saveOrUpdateShortcut (form) {
  const url = form.id ? 'app/sysAppShortcut/update' : 'app/sysAppShortcut/save'
  return http.post(url, form)
}

/**
 * 删除快捷
 * @param {Long} id
 */
export function delShortcut (id) {
  return http.get('app/sysAppShortcut/del/' + id)
}

/** 统计数据 **/

/**
 * 统计分页
 * @param {Object} params
 */
export function statPage (params) {
  return http.post('app/sysAppStat/page', params)
}

/**
 * 统计数据获取排序号
 * @param {Object} formStat
 */
export function getStatOrder (formStat) {
  return http.post('app/sysAppStat/getOrderNo', formStat)
}

/**
 * 根据ID 找统计数据
 * @param {Long} id 主键ID
 */
export function getStatById (id) {
  return http.get('app/sysAppStat/getById/' + id)
}

/**
 * 修改保存统计
 * @param {Object} form
 */
export function saveOrUpdateStat (form) {
  const url = form.id ? 'app/sysAppStat/update' : 'app/sysAppStat/save'
  return http.post(url, form)
}

/**
 * 删除统计
 * @param {Long} id
 */
export function delStat (id) {
  return http.get('app/sysAppStat/del/' + id)
}

/**
 * 获取应用主题接口
 * @param {} record
 * @returns
 */
export function themeGallery (record) {
  return http.get('/app/SysPortalAppTheme/list/' + record.appId, record)
}

/**
 *保存应用主题图片数据
 * @param {*} record
 * @returns
 */
export function saveOrUpdateAppTheme (record) {
  return http.post('/app/SysPortalAppTheme/saveOrUpdate', record)
}

/**
 * 获取应用快捷方式主题接口
 * @param {} record
 * @returns
 */
export function themeShortcutGallery (record) {
  return http.get('/app/SysPortalShortcutTheme/list/' + record.id, record)
}

/**
 * 保存应用快捷方式主题图片数据
 * @param {} record
 * @returns
 */
export function saveOrUpdateShortcutTheme (record) {
  return http.post('/app/SysPortalShortcutTheme/saveOrUpdate', record)
}

/**
 * 同步日志
 * @param {*} param
 * @returns
 */
export function syncLogPage (param) {
  return http.post('/app/sysSyncLog/page', param)
}

/**
 * 同步日志详情
 * @param {*} param
 * @returns
 */
export function syncLogInfoPage (param) {
  return http.post('/app/sysSyncLogInfo/page', param)
}

/**
 * 通过单位ID获取已授权全部用户列表
 */
export function unitByIdUserlist (param) {
  return http.post('/app/sysPortalAppOrder/unitByIdUserlist', param)
}
/**
 * 用户ID列表
 * @param {Object} params
 */
export function getUserIds (params) {
  return http.post('/app/sysPortalAppOrder/getUserIds', params)
}

export function getAesKey (params) {
  return http.get('/app/sysApplication/getAesKey')
}

export function getiAppauth (id) {
  return http.get('app/sysApplicationUnit/info/' + id)
}
export function getiAppauthUser (id) {
  return http.get('app/sysPortalAppOrder/info/' + id)
}
/**
 *应用分类分页列表
 * @param {Object} params
 */
export function getAppClassPageList (params) {
  return http.post('/app/SysAppClassification/page', params)
}

export function getClassById (id) {
  return http.get('/app/SysAppClassification/getById/' + id)
}

/**
 *应用分类列表
 * @param {Object} params
 */
export function saveAppClass (params) {
  return http.post('/app/SysAppClassification/save', params)
}
/**
 *应用分类列表
 * @param {Object} params
 */
export function getAppClassList (params) {
  return http.post('/app/SysAppClassification/list', params)
}

/**
 *删除应用分类
 * @param {Object} id
 */
export function delAppClass (id) {
  return http.get('/app/SysAppClassification/del/' + id)
}

/**
 *修改分类启用状态
 * @param {Object} params
 */
export function updateStatusAppClassById (id) {
  return http.get('/app/SysAppClassification/status/' + id)
}

/**
 *修改分类启用状态
 * @param {Object} params
 */
export function getMaxOrderNo (params) {
  return http.get('/app/SysAppClassification/getMaxOrderNo', params)
}

export function saveAppUser (params) {
  return http.post('app/sysApplicationUser/save', params)
}

export function getUnitUser (appId) {
  return http.get('/app/sysPortalAppOrder/getUnitUser/' + appId)
}

export function authUnitApp (params) {
  return http.post('/app/sysApplicationUnit/authApp', params)
}

export function getAuthUnitApp (unitId) {
  return http.get('/app/sysApplicationUnit/info/' + unitId)
}
export function getUserInfoByUnitId (params) {
  return http.post('/app/sysPortalAppOrder/getUserInfoByUnitId', params)
}
export function getAuthUnitUserTree (topId) {
  return http.get('/app/sysApplicationUnit/getAuthUnitUserTree/' + topId)
}
export function saveAuthApp (params) {
  return http.post('/app/sysPortalAppOrder/saveAuthApp', params)
}
export function getApp (unitUserId) {
  return http.get('/app/sysPortalAppOrder/getApp/' + unitUserId)
}
export function getAuthList (param) {
  return http.post('app/sysApplicationUser/getAuthList', param)
}

// 字段配置相关接口
/**
 *根据应用id查询字段列表
 * @param {Object} params
 */
export function getAppfieldByAppId (param) {
  return http.post('/app/sysApplicationField/queryList', param)
}

/**
 *保存单个字段配置
 * @param {Object} params
 */
export function saveAppfieldInfo (param) {
  return http.post('/app/sysApplicationField/save', param)
}

/**
 *删除单个字段配置
 * @param {Object} params
 */
export function deleteAppfieldByAppId (id) {
  return http.get(`/app/sysApplicationField/del/${id}`)
}

/**
 * 获取用户应用列表数据  过期
 * @returns
 */
export function getUserAppList () {
  return http.get('/app/sysPortalAppOrder/getUserAppList/1')
}

/**
 * 获取用户应用列表数据 魔粒 新
 * @returns
 */
export function getUserAllAppList () {
  return http.get('/app/sysPortalAppOrder/getAppPortalAll/1')
}
/**
 * 根据 应用编码获取应用URL
 * @param {*} appCode
 * @returns
 */
export function getApplicationURLByCode (appCode) {
  return http.get('/app/sysApplication/appCode/' + appCode, {
    needToken: true
  })
}

/**
 * 根据类型查询常用功能
 */
export function getPopularApplicationByType (type) {
  return http.post('/app/sysPopular/queryList', { type })
}

/**
 * 保存常用功能
 */
export function savePopularApplication (params) {
  return http.post('/app/sysPopular/save', params)
}